#include "AABB.h"
#include "OBB.h"
AABB::AABB()
{
}

AABB::AABB( D3DXVECTOR4 *vertices,  unsigned int count  )
{
	Generate(vertices, count);
}

void AABB::Generate( D3DXVECTOR4 *vertices, unsigned int count  )
{
	min = D3DXVECTOR4( FLT_MAX, FLT_MAX, FLT_MAX, 0.f );
	max = D3DXVECTOR4( -FLT_MAX, -FLT_MAX, -FLT_MAX, 0.f );

	for( size_t i = 0; i < count; ++i )
	{
		min.x = min( min.x, vertices[i].x );
		min.y = min( min.y, vertices[i].y );
		min.z = min( min.z, vertices[i].z );

		max.x = max( min.x, vertices[i].x );
		max.y = max( min.y, vertices[i].y );
		max.z = max( min.z, vertices[i].z );
	}
}

void AABB::RebuildAABB()
{
	/*OBB obb;
	D3DXVECTOR3 *vrts = obb.GetVertices();

	vrts[0] = min;
	vrts[1] = D3DXVECTOR3( max.x, min.y, min.z, 1 );
	vrts[2] = D3DXVECTOR3( max.x, max.y, min.z, 1 );
	vrts[3] = D3DXVECTOR3( min.x, max.y, min.z, 1 );
												
	vrts[4] = max;								
	vrts[5] = D3DXVECTOR3( min.x, max.y, max.z, 1 );
	vrts[6] = D3DXVECTOR3( min.x, min.y, max.z, 1 );
	vrts[7] = D3DXVECTOR3( max.x, min.y, max.z, 1 );

	for( size_t i = 0; i < 8; ++i )
		D3DXVec4Transform( &vrts[i], &vrts[i], &transform );
	Generate( vrts, 8 );*/
};

D3DXVECTOR4 AABB::GetMin()
{
	return min;
}

D3DXVECTOR4 AABB::GetMax()
{
	return max;
}